package com.jdk.demo.io.so_lingerDemo.demo4;

import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

	public static void main(String[] args) throws Exception {
		StringBuffer buffer = new StringBuffer(1000000);
		for (int i = 0; i < 1000000; i++) {
			buffer.append("1");
		}
		buffer.append("end");
		System.out.println("server填充完毕！");

		ServerSocket serverSocket = new ServerSocket(8888);
		Socket socket = serverSocket.accept();
		socket.setSendBufferSize(1000000);
		socket.setSoLinger(true, 1);

		OutputStream out = socket.getOutputStream();
		out.write(buffer.toString().getBytes());

		long begin = System.currentTimeMillis();
		long end = 0;
		System.out.println("C=" + begin);
		socket.close();
		end = System.currentTimeMillis();
		System.out.println("D=" + end);
		System.out.println("阻塞时间差=" + (end - begin));
		serverSocket.close();
		// close方法阻塞1s，并且服务端还发送rst标记，客户端输出异常
	}

}
